<?php

class FDProfileForm extends Zend_Form
{
    private $picture_path = "";
	private $funeral_director = null;
	
    public function __construct($options=array())
    {
        parent::__construct($options);

		$this->user_profile = $options['user_profile'];

		if(isset($this->funeral_director['photo']))
			$this->picture_path = ART_BASE."/FD/".$this->funeral_director['photo'];
					
		$account_exists = false;
		$can_edit_account = false;
		$can_edit_username = false;
		
        // set form name and POST
        $this->setName('fd_profile');
        $this->setMethod('post');
        $this->setEnctype('multipart/form-data');
        
        // create basic field decorators
        $basicDecorators = array(
            'ViewHelper',
            array('Errors', array('placement'=>'append')),
            //array(array('labelBr'=>'HtmlTag'), array('tag'=>'br')),
            array('Label', array('placement'=>'prepend')),
            array( array('outerDiv'=>'HtmlTag'), array('tag'=>'div', 'style'=>'margin-top:5px')),
        );
  
		$style = 'font-size:14pt';
		
 		$f_lname = new Zend_Form_Element_Text( 'lname', array('label'=>'Last Name:', 'size'=>'30', 'style'=>$style ) );
//		$f_lname->setRequired(true);
		$f_lname->setDecorators($basicDecorators);
		
 		$f_fname = new Zend_Form_Element_Text( 'fname', array('label'=>'First Name:', 'size'=>'30', 'style'=>$style ) );
//		$f_fname->setRequired(true);
		$f_fname->setDecorators($basicDecorators);
		
 		$f_mname = new Zend_Form_Element_Text( 'mname', array('label'=>'Middle Name:', 'size'=>'30', 'style'=>$style) );
		$f_mname->setDecorators($basicDecorators);
		
		$f_suffix = new Zend_Form_Element_Text( 'suffix', array('label'=>'Suffix:', 'size'=>'10', 'style'=>$style) );
		$f_suffix->setDecorators($basicDecorators);
		
		$f_title = new Zend_Form_Element_Text( 'title', array('label'=>'Title:', 'size'=>'10', 'style'=>$style) );
		$f_title->setDecorators($basicDecorators);
		
 		$f_email = new Zend_Form_Element_Text( 'email', array('label'=>'Email:', 'size'=>'40', 'style'=>$style) );
		$f_email->setDecorators($basicDecorators);
		
 		$f_phone = new Zend_Form_Element_Text( 'phone', array('label'=>'Phone:', 'size'=>'16', 'style'=>$style) );
		$f_phone->setDecorators($basicDecorators);
				
		$f_password = new Zend_Form_Element_Text( 'password', array('label'=>'Password:', 'size'=>'20', 'style'=>$style) );
		$f_password->setDecorators($basicDecorators);
		
		$f_notes = new Zend_Form_Element_Textarea( 'notes' );

// change this to FDMS license number and make it readonly?

//		$f_VAS_fd_id = new Zend_Form_Element_Hidden('VAS_fd_id');
		$f_VAS_fd_id = new Zend_Form_Element_Text('VAS_fd_id');
		$f_VAS_fd_id->setValue( $this->VAS_fd_id );
		
        // form's submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Submit');

        $this->addElements( array( $f_VAS_fd_id, $f_fname, $f_mname, $f_lname, $f_suffix, $f_title ) );
		$this->addElements( array( $f_phone, $f_email ) );
		
		if($this->ks_form)
		{
			$f_username = new Zend_Form_Element_Text( 'username', array('label'=>'Username:', 'size'=>'20', 'style'=>$style) );
			$f_username->setDecorators($basicDecorators);
			$this->addElements( array( $f_username, $f_password ));
		}
		
		$this->addDisplayGroup( array( 'fname', 'mname', 'lname', 'suffix', 'title' ), "Identity" );
		$this->addDisplayGroup( array( 'phone', 'email' ), "Contact" );
				
	//	$this->addDisplayGroup( array( $f_phone, $f_username ), "Contact Info" );
	//	$this->addDisplayGroup( array( $f_username, $f_password ), "User Account" );
		
        $this->addElements( array($submit) );
    }

    // dirt-simple template engine.
    public function render_with_template( $template_name )
    {
        $template_file_path = APP_DIR."/views/templates/$template_name";
        $template_contents = file_get_contents( $template_file_path );

        // str_replace() keywords, adding errors where needed
        $form_elements = $this->getElements();

		$template_contents = str_replace( "{FORM_ACTION}", $this->getAction(), $template_contents );
		$template_contents = str_replace( "{FORM_ENCODING}", $this->getEnctype(), $template_contents );

 		$template_contents = str_replace( "{FUNERAL_DIR_ID}", $form_elements['VAS_fd_id'], $template_contents );
		
 		$template_contents = str_replace( "{FUNERAL_DIR_FNAME}", $form_elements['fname'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_MNAME}", $form_elements['mname'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_LNAME}", $form_elements['lname'], $template_contents );

        $template_contents = str_replace( "{FUNERAL_DIR_SUFFIX}", $form_elements['suffix'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_TITLE}", $form_elements['title'], $template_contents );

        $template_contents = str_replace( "{FUNERAL_DIR_PHONE}", $form_elements['phone'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_EMAIL}", $form_elements['email'], $template_contents );
 
		if($this->ks_form)
		{
			$fUsername = "Username:<br>{$this->funeral_director['username']}";
		}
		else
		{
			$fUsername = $form_elements['username'];
		}
		
        $template_contents = str_replace( "{FUNERAL_DIR_USERNAME}", $fUsername, $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_PASSWORD}", $form_elements['password'], $template_contents );
		
        $template_contents = str_replace( "{FUNERAL_DIR_IMAGE_PATH}", $this->picture_path, $template_contents );

		$file_upload = "<input type=file name=\"photo\">";		
//        $template_contents = str_replace( "{FUNERAL_DIR_IMG_FILE}", $form_elements['photo'], $template_contents );
        $template_contents = str_replace( "{FUNERAL_DIR_IMG_FILE}", $file_upload, $template_contents );


        $template_contents = str_replace( "{SUBMIT_BUTTON}", $this->submit, $template_contents );
        
        echo $template_contents;
    }
}

?>
